package commonClass;

import java.util.Calendar;

/**
 * 第二代日期类 Calendar
 */
public class Calendar_ {

    public static void main(String[] args) {

        /*
            Calendar类是一个抽象类，它为特定瞬间与一组诸如 YEAR、MONTH、DAY_OF_MONTH、HOUR等日历字段
            提供了一些方法，并为操作日历字段提供了一些方法
         */

        Calendar c = Calendar.getInstance();
        System.out.println("c = " + c);

        //2.获取日历对象的某个日历字段
        System.out.println("年："+c.get(Calendar.YEAR));
        //这里为什么要+1,因为Calendar返回月时候，是按照0开始编号
        System.out.println("月："+(c.get(Calendar.MONTH)+1));
        System.out.println("日："+c.get(Calendar.DAY_OF_MONTH));
        System.out.println("小时："+c.get(Calendar.HOUR));
        System.out.println("分钟："+c.get(Calendar.MINUTE));
        System.out.println("秒："+c.get(Calendar.SECOND));

        System.out.println(c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH) + 1) + "-" +
                c.get(Calendar.DAY_OF_MONTH)+
                " "+c.get(Calendar.HOUR_OF_DAY)+":"+c.get(Calendar.MINUTE)+":"+c.get(Calendar.SECOND));
    }
}
